<?php
/**
 * @copyright: ©2024 永州微聚 商网络科技有限公司
 * @link: https://www.weijuYunke.com
 */
namespace app\api\controller\consume;

use app\admin\service\TriggerService;
use app\common\controller\AdminController;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use app\admin\service\NodeService;
use think\App;
use think\Model;
use app\admin\model\FigureIndexSet;
use app\admin\model\FigureSystem;

/**
 * @ControllerAnnotation(title="配置管理")
 * Class Node
 *
 * @package app\admin\controller\system
 */
class System extends AdminController
{

    use \app\admin\traits\Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = new \app\admin\model\FigureSystem();
    }

    /**
     * 查询代理系统设置
     * @NodeAnotation(title="查询系统设置")
     */
    public function querySystem()
    {
        $request = $this->request;
        $user_id = $request->_UID;
        $system = FigureSystem::where("id", 1)->find();
        unset($system['create_time']);
        unset($system['update_time']);
        unset($system['delete_time']);
        return msg($system, 0, "");
    }

    /**
     * 保存代理系统设置
     * @NodeAnotation(title="代理系统设置")
     */
    public function saveSystem()
    {
        $post = $this->request->post();

        $user_id = $this->request->_UID;
        try {

            unset($post['template_type']);

            $system = FigureSystem::where("id", 1)->find();
            if (empty($system)) {
                $set = new FigureSystem();
                $set->save($post);
            } else {
                FigureSystem::where("id", 1)->save($post);
            }
        } catch (\Exception $e) {
            return msg([], 1, "保存异常" . $e->getMessage());
        }
        return msg([], 0, "保存成功");
    }
}